<template>
	<el-dialog title="帖子信息" :visible.sync="dialogFormVisible" :before-close="cleardata">
		<el-form :model="form">
			<el-form-item label="创建人" :label-width="formLabelWidth">
				<el-input v-model="form.nickName" autocomplete="off" style="width: 40%;" :disabled="true"></el-input>
			</el-form-item>
			<el-form-item label="标题" :label-width="formLabelWidth">
				<el-input v-model="form.messTitle" autocomplete="off" style="width: 40%;"></el-input>
			</el-form-item>
			<el-form-item label="资讯内容" :label-width="formLabelWidth">
				<div ref="editor"></div>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="cleardata">取 消</el-button>
			<el-button type="primary" @click="editZnMessage">确 定</el-button>
		</div>
	</el-dialog>
</template>

<script>
	import znMessApi from "@/api/znMessage.js"
	import Editor from "wangeditor"
	export default {
		components: {
		},
		data() {
			return {
				editor: null,
				dialogFormVisible: false,
				form: {
					znMessId: "",
					messTitle: "",
					messContent: "",
				},
				formLabelWidth: '120px'
			};
		},
		methods: {
			//创建富文本容器
			createE(){
				this.$nextTick(()=>{
					this.editor = new Editor(this.$refs.editor)
					this.editor.config.uploadImgServer = "api/file/editUpload/posts"
					this.editor.config.uploadFileName = "file"
					this.editor.config.uploadVideoServer = 'api/file/editVideoUpload/posts'
					this.editor.config.uploadVideoName = "file"
					this.editor.create()
					this.editor.txt.html(this.form.messContent)
				})
			},
			cleardata() {
				this.dialogFormVisible = false;
				this.editor.destroy();
			},
			async editZnMessage() {
				let content = this.editor.txt.html();
				const res = await znMessApi.editZnMessage("/znMessage/editZnMessage", {
					znMessId: this.form.znMessId,
					messTitle: this.form.messTitle,
					messContent: this.form.messContent = content,
				});
				if (res.code == 200) {
					this.cleardata();
					this.$parent.SearchZnMessageAll();
					this.$message.success("成功");
				}else{
					this.$message.warning("失败");
				}
			}
		},
	};
</script>

<style lang="scss" scoped>
	.avatar {
	  float: left;
	  width: 148px;
	  height: 148px;
	  border-radius: 3%;
	  margin-right: 10px;
	  }
</style>